package com.compass.doctor.ui.setting.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.compass.framework.model.ConsultSetting
import com.compass.framework.model.Dictionaries
import com.compass.framework.toast.TipsToast
import com.compass.network.callback.IApiErrorCallback
import com.compass.network.manager.ApiManager
import com.compass.network.viewmodel.BaseViewModel

/**
 * Description： 咨询设置viewModel
 * Date:2023/12/19 9:41
 */
class ConsultSettingViewModel : BaseViewModel() {

    val consultLiveData: MutableLiveData<ConsultSetting?> = MutableLiveData()
    val saveConsultLiveData: MutableLiveData<Boolean?> = MutableLiveData()
    val dictionariesLiveData = MutableLiveData<MutableList<Dictionaries>?>()

    fun getDictionaries(typeValue :String) :LiveData<MutableList<Dictionaries>?>{
        launchUIWithResult(responseBlock = {
            ApiManager.api.getDictionaries(typeValue)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                dictionariesLiveData.value=null
            }
        }, successBlock = {
            dictionariesLiveData.value=it
        })

        return dictionariesLiveData
    }


    fun getConsultationConfig(): LiveData<ConsultSetting?> {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getConsultationConfig()
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                consultLiveData.value = null
            }
        }, successBlock = {
            consultLiveData.value = it
        })
        return consultLiveData
    }

    fun saveConsultationConfig(consultSetting: ConsultSetting?){
        launchUIWithResult(responseBlock = {
            ApiManager.api.updateConsultationConfig(consultSetting)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                saveConsultLiveData.value = false
            }
        }, successBlock = {
            saveConsultLiveData.value = true
        })
    }
}